<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增用户信息</title>
    <script src="../../assets/js/jquery-2.0.3.min.js"></script>
    <script src="../../assets/js/bootstrap.min.js"></script>
    <script src="../../assets/js/hammer.min.js"></script>
    <script src="../../assets/js/jquery.extend.js" type="text/javascript"></script>
    <script src="../../assets/js/jquery.scrolltopcontrol/scrolltopcontrol.js"></script>
    <script src="../../assets/js/bootstrap.table/bootstrap-table.min.js" type="text/javascript"></script>
    <script src="../../assets/js/bootstrap.table/bootstrap-table-zh-CN.min.js" type="text/javascript"></script>
    <script src="../../assets/js/dialog.js"></script>
    <script src="../../assets/js/jquery.cookie.js" type="text/javascript"></script>
    <script src="../../assets/js/common.js" type="text/javascript"></script>
    <script src="../../assets/js/myUrl.js" type="text/javascript"></script>

    <link href="../../assets/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="../../assets/css/bootstrap.table/bootstrap-table.min.css" rel="stylesheet" type="text/css"/>
    <link href="../../assets/css/dialog.css" rel="stylesheet" />
    <link href="../../assets/css/common.css" rel="stylesheet" type="text/css"/>
</head>
<body style="padding: 0px 6px 0px 6px;overflow-x: hidden;overflow-y: scroll">
<div class="addEdit-title" >
    <h4>新增用户</h4>
</div>
<div style="width: 100%;margin-top: 10px;">
    <form class="form-horizontal" id="articleForm" role="form">
        <div class="form-group">
            <label class="col-sm-2 control-label">登录名<span style="color: red;">*</span></label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="userName" name="userName" onBlur="onBlurValue(this)" placeholder="请输入登录名">
                <span class="help-block" style="color: red; display: none;">请输入登录名</span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">密码<span style="color: red;">*</span></label>
            <div class="col-sm-7">
                <input type="text" class="form-control" style="width: 30%" id="userPassword" name="userPassword" onBlur="onBlurValue(this)"  placeholder="请输入用户名称">
                <span class="help-block" style="color: red; display: none;">请输入用户密码</span>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-12 control-label" style="text-align: center;">
                <button type="button" class="btn btn-default" onclick="cancelUser(this)">取消</button>
                <button type="button" class="btn btn-primary" onclick="saveUserInfo(this);">确定</button>
            </label>
        </div>
    </form>
</div>
<a href="#top" id="goTop"><i class="fa fa-angle-up fa-3x"></i></a>
</body>
<script type="text/javascript">
    var idarticle = "";

    $(function () {
        //判断是修改还是新增
        idarticle = getQueryString("id");
        if(idarticle!=null&&idarticle!=""){
            $(".addEdit-title").html("<h4>修改用户内容</h4>");
            getUserInfo(idarticle);
        }

    })

    function saveUserInfo(e){

        var b = saveCheckInfo();
        if(!b){
            return false;
        }
        $(e).attr("disabled","disabled");
        var data ={};
        data["userName"] = $("#userName").val();
        data["userPassword"] = $("#userPassword").val();
        if(idarticle==null||idarticle==""){//保存
            var url = local_url.user_add;
            var result = myAjaxJSON(data, url, "PUT");
            if(result.code==="200"){
                okDail("保存成功！","/html/system/userInfo.html");
            }else {
                errorDail("保存失败!");
            }
        }else {//修改'
            data["id"] = idarticle;
            var url = local_url.user_edit;
            var result = myAjaxJSON(data, url, "PUT");
            if(result.code==="200"){
                okDail("修改成功！","/html/system/userInfo.html?btnPurid="+btnPurid);
            }else {
                errorDail("修改失败!");
            }
        }

    }

    //判断是否为空
    function saveCheckInfo(){
        var b = true;
        b = checkValue("userName");
        b = checkValue("userPassword");
        return b;
    }

    function getUserInfo(id) {
        var opt = {"userId":id};
        var result = myAjax(opt, local_url.user_info, "GET");
        if(result.code==="200"){
            var  message = result.data;
            $("#userName").val(message.userName);
            $("#userPassword").val(message.userPassword);

        }else{
            errorDail("获取信息失败!");
        }
    }

    function cancelUser() {
        window.location.href="/html/system/userInfo.html?btnPurid="+btnPurid;
    }
</script>
</html>